// 类型注解
let data1: number = 1;
let data2: string = '1';
let data3: boolean = true;
let data4: null = null;
let data5: undefined = undefined;
// 类型推断
let data6 = '1123'

let obj1: {
    id: number,
    name: string,
    age?: number
} = {
    id: 1,
    name: 'kkk',
    age: 1
}
interface data2 {
    phone: number,
    email: string
}
interface person3 {
    id: number,
    name: string,
    age?: number,
    data: data2
}
let obj233: person3 = {
    id: 1,
    name: 'kkk',
    age: 1,
    data: {
        phone: 136999999,
        email: "222@.qq.com"
    }
}
// type 类似于interface缺点是不能嵌套
type person4 = {
    id: number,
    name: string,
    age?: number,
    data: {
        phone: number,
        email: string
    }
}
let objjj: person4 = {
    id: 1,
    name: 'kkk',
    age: 1,
    data: {
        phone: 136999999,
        email: "222@.qq.com"
    }
}


const fun1: (id: number, name: string) => boolean = (id, name) => {
    return true
}

function fun2(id: number, name: string): string {
    return ''
}
fun2(1, '1')

function fun3(): void { //  void 函数不能有返回值
    // return 123
}

function fun4(): never { // 函数不能结束
    while (true) {

    }
}

type person5 = {
    id: number,
    name: string
}
function fun5(data: { id: number, name: string } | person5) {

}
fun5({ id: 1, name: "kkk" })
function fun6({ id, name }: { id: number, name: string }) {

}
fun6({ id: 1, name: "kkk" })

// 数组
let arr1: [string, number, string, number] = ['1', 1, '1', 1]; // 元祖  当一个数组长度固定时就是一个元祖
let arr2: (string | number)[] = ['1', 1, '1', 1, '1'];
let arr3: ({ id: number, name: string })[] = [{ id: 1, name: 'kkk' }, { id: 2, name: 'bbb' }]
type listType = {
    id: number, name: string
}
let arr4: (listType)[] = [{ id: 1, name: 'kkk' }, { id: 2, name: 'bbb' }]
let arr5: [string, number, string, number][] = [['1', 1, '1', 1]];


// interface 
interface Person5 {
    readonly name: string; // 只读
    age?: number; // 非必填 
    // say(word: string): string; // 需要一个say方法 返回值必须是string
    say: SayHi;
    [propName: string]: any;// 允许任何一个名词为字符串 类型是any的值

}


let obj10: Person5 = {
    name: "123",
    say: () => {
        return ""
    },
    a: 1,
    b: 2,
    c: 3
}

// interface 继承
interface Teacher extends Person5 {
    teach(): string;
}

// interface 声明函数类型
interface SayHi {
    (word: string): string;// 声明函数参数必须有word 必须返回一个string
}

// 枚举
enum Family { Mom = '女', Father = "男", Me = "男" }
// let FamilyList: Family;
console.log(Family.Mom)
console.log(Family.Father)
console.log(Family.Me)
// 泛型
function fun100<T, P>(data: T, id: P): T {
    return data
}
fun100<number, string>(1, '1')